I was trying to figure out what these are. I understand the following (from the manual):
BIN: converts BCD (Binary Coded Decimal) format to binary format
BCD: converts binary format to BCD format
While experimentibg on 0iTC, I found the following:
BIN [41] returns 29.000
BCD [29] returns 41.000
BIN [10] illegal argument
BCD [1000] returns 4096.000
BCD[1000000] returns 16777216.
BCD[a negative value] illegal argument
BCD [fractional value] rounding to the nearest integer is automatically done, and then function is evaluated.
etc.
I could not derive any logic out of it. Can somebody please these explain these function is some detail.
In binary coding each bit represents a power of two. In BCD the bits are grouped in fours and each group of four represents a decimal digit.
The numeric parameter is always converted to binary and then passed to the functions so:
BIN[41]: 41 in binary is 101001, interpreted in BCD that is 0010, 1001 i.e. 29.
BCD[29] 29 in BCD is 0010, 1001, intepreted in binary is 101001 , i.e. 32+9 =41
BIN[10] is illegal because binary 10 is 1010 which is not a BCD digit.
BCD[1000] is 0001 0000 0000 0000 which is 2^12 i.e. 4096 when interpreted in binary.
BCD[1000000] is 2^24
Thanks.
So, BIN converts a binary number to BCD
and BCD converts a BCD to binary.
Peter Smid also says the same thing in his book, but Fanuc manual says the opposite:
(from Operator's Manual 0i Tc, page 266) Conversion from BCD to BIN, #i = BIN [#j];
Conversion from BIN to BCD, #i = BCD [#j];
This is the result of Japanese to English translation.
No BIN converts a BCD number to binary. BCD converts binary to BCD.
The really confusing thing is that your input and output functions in the examples are always converting ascii to binary and binary to ascii. When you do BCD[29] the text 29 is converted to binary 11101 (16 + 8 + 4 + 1). The BCD function converts it to the BCD representation of 29 which 0010 1001. That is converted back to ascii to print the result but the conversion does not know it should be interpreted in BCD so it shows its binary value which is 32 + 8 + 1 = 41.
The BCD representation only makes sense if it is sent to something that expects it to be BCD, for example the BIN function.
Thanks again.
Somebody told me that these functions have something to do with the interface signals, for the purpose of interacting with external devices connected to CNC. Can you please give just one example of these functions.